package com.tankwar.transport;

import com.swak.exception.RemotingException;
import com.swak.reactivex.transport.Channel;
import com.swak.reactivex.transport.ExchangeClient;
import com.swak.reactivex.transport.ExchangeHandler;
import com.swak.reactivex.transport.ExchangeHandlerAdapter;
import com.swak.reactivex.transport.Exchangers;
import com.swak.reactivex.transport.resources.LoopResources;
import com.swak.registry.URL;

public class TankwarClient {

	private ExchangeClient client;
	private ExchangeHandler exchangeHandler = new ExchangeHandlerAdapter() {

		@Override
		public void received(Channel channel, Object message) throws RemotingException {
			TankwarClient.this.received(channel, message);
		}
	};

	public TankwarClient(URL url, LoopResources resources) throws RemotingException {
		this.client = Exchangers.connect(url, resources, exchangeHandler);
	}

	public void close() {
		this.client.close();
	}

	/**
	 * 外部可以调用此来发送数据
	 * 
	 * @param message
	 * @throws RemotingException
	 */
	public void sent(Object message) throws RemotingException {
		client.send(message);
	}

	/**
	 * 收到数据处理
	 * 
	 * @param channel
	 * @param message
	 */
	private void received(Channel channel, Object message) {

	}
}
